package com.linkhub.oms.dao.mpservice.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.linkhub.oms.dao.mapper.EntryOrderResultEntityMapper;
import com.linkhub.oms.dao.mpservice.IEntryOrderResultService;
import com.linkhub.oms.entity.EntryOrderResultEntity;
import com.linkhub.oms.entity.LocalProductEntity;
import com.linkhub.oms.entity.PickUpGoodsOrderEntity;
import com.linkhub.oms.entity.resulttype.entryorder.EntryOrderResultMapEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 提货结果表 服务实现类
 * </p>
 *
 * @author echo
 * @since 2024-04-30
 */
@Service
public class EntryOrderResultServiceImpl extends ServiceImpl<EntryOrderResultEntityMapper, EntryOrderResultEntity> implements IEntryOrderResultService {
    @Resource
    private EntryOrderResultEntityMapper entryOrderResultEntityMapper;

    @Override
    public List<EntryOrderResultMapEntity> queryEntryOrderResults(String sysEntryOrderCode) {
        MPJLambdaWrapper<EntryOrderResultEntity> wrapper = JoinWrappers.lambda(EntryOrderResultEntity.class);
        wrapper.selectAll(EntryOrderResultEntity.class)
                .selectAs(PickUpGoodsOrderEntity::getStorageTime, EntryOrderResultMapEntity::getStorageTime)
                .selectAs(LocalProductEntity::getSku, EntryOrderResultMapEntity::getSku)
                .selectAs(LocalProductEntity::getProductEnTitle, EntryOrderResultMapEntity::getProductEnTitle)

                .leftJoin(PickUpGoodsOrderEntity.class, on ->
                        on.eq(PickUpGoodsOrderEntity::getSysEntryOrderCode, EntryOrderResultEntity::getSysEntryOrderCode))

                .leftJoin(LocalProductEntity.class, on ->
                        on.eq(LocalProductEntity::getSkuId, EntryOrderResultEntity::getSkuId))

                .eq(EntryOrderResultEntity::getSysEntryOrderCode, sysEntryOrderCode);

        return entryOrderResultEntityMapper.selectJoinList(EntryOrderResultMapEntity.class, wrapper);
    }
}
